package csci4448.android.workouttracker;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;

public class ViewSession extends Activity {
	
	private Integer sessionID;
	private SessionModel _model = new SessionModel(this);
	private TextView DistanceView;
	private TextView TimeView;
	private TextView AverageSpeedView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_view_session);
		sessionID = getIntent().getIntExtra("id", -1);
		TimeView = (TextView)findViewById(R.id.ViewTimeElapsedValue);
		DistanceView = (TextView)findViewById(R.id.ViewTotalDistanceValue);
		AverageSpeedView = (TextView)findViewById(R.id.ViewAverageSpeedValue);
		populateDataFields();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_view_session, menu);
		return true;
	}
	
	public void onBackButtonClick(View view){
		finish();
	}
	
	public void populateDataFields() {
		Session s;
		try {
			s = _model.getSessionById(sessionID);
			TimeView.setText(s.getDurationString());
			DistanceView.setText(s.getDistanceString());
			AverageSpeedView.setText(s.getSpeedString());
		} catch (Exception e) {}
	}

}
